// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
import operationRouter from './modules/operation'
import departmentRouter from './modules/department'
import personRouter from './modules/person'
import electronicRouter from "./modules/electronic";
import computerRouter from "./modules/computer";
import testsRouter from "./modules/tests";
import modelTypeRouter from "./modules/modelType";
import incidentRouter from "./modules/incident";
import backupsRouter from "./modules/backups";
import workshopRouter from "./modules/workshop";
import protectionPointRouter from "./modules/protectionPoint";
import messageRouter from "./modules/message";
import maintainRouter from './modules/maintain'
import enjoyRouter from './modules/enjoy'
import ammunitionRouter from './modules/ammunition'
import carRouter from './modules/car'
import privateCarRouter from './modules/privateCar'
import equipRouter from './modules/equip'
import taskRouter from './modules/task'

import userRouter from './modules/user'
import mobileRouter from './modules/mobile'
import finance from '@/router/modules/finance'
import yearTaskRouter from '@/router/modules/yearTask'
import other from '@/router/modules/other'
export const constantRoutes = [
  other,
  finance,
  // 设置
  operationRouter,
  //单位部门
  departmentRouter,
  //人员
  personRouter,
  //个人电子设备
  electronicRouter,
  //办公计算机
  computerRouter,
  //试验
  testsRouter,
  //事件
  incidentRouter,
  //型号
  modelTypeRouter,
  //数据
  backupsRouter,
  //技术阵地/厂房
  workshopRouter,
  //保护点信息
  protectionPointRouter,
  //福利费享受信息
  enjoyRouter,
  //消息通知
  messageRouter,
  // 维护
  maintainRouter,
  //车辆
  carRouter,
  //私家车
  privateCarRouter,
  //装备
  equipRouter,
  //弹药检测数量统计
  ammunitionRouter,
  //任务进度管理
  taskRouter,
  //年任务
  yearTaskRouter,
  // 会员
  userRouter,
  //移动端管理
  mobileRouter,

  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/auth-send',
    component: () => import('@/views/mobile/auth-send'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '主页', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    path: '/enter',
    component: () => import('@/views/enter/index'),
    hidden: true
  },
  {
    path: '/setting/uploadPicture',
    component: () => import('@/components/uploadPicture/index.vue'),
    name: 'uploadPicture'
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  //mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
